<?php
if (!defined('CMS_SYSTEM')) die();
if ($disable_site) {
	echo "<center style=\"margin-top:200px;font-weight:bold\">".$disable_message ."</center>";
}else{
$catid = intval($_GET['catid']);
$result = $db->sql_query("SELECT title, sub_id, parentid FROM ".$prefix."_products_cat WHERE catid='$catid' AND alanguage='$currentlang'");
if(empty($catid) || $db->sql_numrows($result) != 1) {
	header("Location: index.php?f=".$module_name);
	exit();
}

list($catname, $sub_id, $parentid) = $db->sql_fetchrow($result);
if ($parentid != 0) {
	$title_cat = page_tilecat($catid, $parentid, $catname);
	$page_title .= " $title_cat";
} else {
	$title_cat = $catname;
	$page_title .= " :: $catname";
}
/*
							   * phan phan trang 
							   * Le duc vien
							   */
							    $perpage = $prd_perpage;
								$page = intval(isset($_GET['page']) ? $_GET['page'] : (isset($_POST['page']) ? $_POST['page']:1));
								$offset = ($page-1) * $perpage;
								
								$pageurl = "index.php?f=".$module_name."&do=categories&catid=$catid";
							  /*
							   * Ket thuc phan phan trag
							   */
include_once("templates/".$Default_Temp."/header.php");
  include_once("templates/".$Default_Temp."/banner.php");
  include_once("templates/".$Default_Temp."/menu.php");
  /*
   * Phan loc ra tat ca san pham
   * Le duc vien
   */
 echo "<div id=\"wrapper\">";
	 echo "<div class=\"content fix\">";
	     //Noi dung phan loc tat ca san pham
		 if (empty($sub_id)) {
		     echo "<div class=\"w720 fl\">";
		       echo "<div class=\"common\">";
		            echo "<div class=\"title\">";
					 echo "<h1 class=\"text\"><a href=\"index.php?f=".$module_name."&do=categories&catid=$catid\"><span>".$catname."</a></h1>";
				    echo "</div>";
				    echo "<div class=\"wrap fix\">";
						$pageurl = "index.php?f=".$module_name."&do=categories&catid=$catid";
						$result_prd_home = $db->sql_query("SELECT id, title, images,price FROM {$prefix}_products WHERE catid='$catid' AND active='1' AND alanguage='$currentlang' ORDER BY time DESC LIMIT $offset, $perpage");
						if($db->sql_numrows($result_prd_home) > 0) {
						    $countf_cate = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM {$prefix}_products WHERE active=1 AND catid='$catid' AND alanguage='$currentlang'"));
							$total_cate = ($countf_cate[0]) ? $countf_cate[0] : 1;
							while(list($id, $title, $images,$price) = $db->sql_fetchrow($result_prd_home)) 
                        	{
                        		$urlid = "$siteurl/".url_sid("index.php?f=$module_name&do=detail&id=$id");
			                	echo "<div class=\"product\">";
									
		                        	if($images=="")
									{  
									   echo "<a href=\"".$urlid."\" class=\"tooltip\" rel=\"<img src='images/nopic2.gif' width='$prd_sizedetail' height='210'/>\" >";
									    echo "<img src=\"images/nopic2.gif\" width='$prd_thumbsize' alt=\"\">";
									   echo "</a>";
									}else {	
									  echo "<a href=\"".$urlid."\" class=\"tooltip\" rel=\"<img src='$path_upload/$module_name/$images' width='$prd_sizedetail' height='210'/>\" >";
										echo "<img src=\"$path_upload/$module_name/$images\" width='$prd_thumbsize' alt=\"\">";
									  echo "</a>";
									}
									
									echo "<p>"._PRICE_PRODUCT.": <strong class=\"f1\">".bsVndDot($price)." VNĐ</strong></p>";
									echo "<a href=\"".url_sid("index.php?f=products&do=cart&act=add&id=$id")."\" class=\"btnBuy\">"._CART_PRODUCT."</a>";
									echo "<a href=\"".url_sid("index.php?f=products&do=detail&id=$id")."\" title=\"$title\">$title</a>";
								echo "</div>";
                        	}
                        	echo "<div class=\"clear\"></div>";			
							if($total_cate > $perpage) {		
											echo "<div class=\"page fix\">";
											   echo "".paging_theme($total_cate,$pageurl,$perpage,$page)."";
										    echo "</div>";
					         }
						}
						else 
						{
							echo "<div style=\"text-align:center;padding-top:10px\">"._PRODUCT_NULL."</div>";
						}
					echo "</div>";
		       echo "</div>";
		     echo "</div>";
		 }
		 else 
		 {
		 	 echo "<div class=\"w720 fl\">";
		       echo "<div class=\"common\">";
		            echo "<div class=\"title\">";
					 echo "<h1 class=\"text\"><a href=\"index.php?f=".$module_name."&do=categories&catid=$catid\"><span>".$catname."</a></h1>";
				    echo "</div>";
				    echo "<div class=\"wrap fix\">";
					 	$result_subcat_prd = $db->sql_query("SELECT catid, title FROM {$prefix}_products_cat WHERE parentid='$catid' AND active=1 AND alanguage='$currentlang' ORDER BY weight");
					 	if($db->sql_numrows($result_subcat_prd) > 0) 
					 	{
					 		$item_list=explode('|', $sub_id);
					 		array_push($item_list,$catid);
					 	    $item_list_tmp = '';
					        foreach ($item_list AS $item)
					        {
					            if ($item !== '')
					            {
					                $item_list_tmp .= $item_list_tmp ? ",'$item'" : "'$item'";
					            }
					        }
					            $countf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM {$prefix}_products WHERE active=1 AND catid IN($item_list_tmp) AND alanguage='$currentlang'"));
								$total = ($countf[0]) ? $countf[0] : 1;
								
					 			$result_prd_home = $db->sql_query("SELECT id, title, images,price FROM {$prefix}_products WHERE catid IN($item_list_tmp) AND active=1 AND alanguage='$currentlang' ORDER BY time DESC LIMIT $offset, $perpage");
					 			if($db->sql_numrows($result_prd_home) > 0) {
					 				while(list($id, $title, $images,$price) = $db->sql_fetchrow($result_prd_home)) 
		                        	{
		                        		$urlid = "$siteurl/".url_sid("index.php?f=$module_name&do=detail&id=$id");
					                	echo "<div class=\"product\">";
											
				                        	if($images=="")
											{  
												echo "<a href=\"".$urlid."\" class=\"tooltip\" rel=\"<img src='images/nopic2.gif' width='$prd_sizedetail' height='210'/>\" >";
											      echo "<img src=\"images/nopic2.gif\" width='$prd_thumbsize' alt=\"\">";
											    echo "</a>";
											}else {
											 echo "<a href=\"".$urlid."\" class=\"tooltip\" rel=\"<img src='$path_upload/$module_name/$images' width='$prd_sizedetail' height='210'/>\" >";	
												echo "<img src=\"$path_upload/$module_name/$images\" width='$prd_thumbsize' alt=\"\">";
											 echo "</a>";
											}
											
											echo "<p>"._PRICE_PRODUCT.": <strong class=\"f1\">".bsVndDot($price)." VNĐ</strong></p>";
											echo "<a href=\"".url_sid("index.php?f=products&do=cart&act=add&id=$id")."\" class=\"btnBuy\">"._CART_PRODUCT."</a>";
											echo "<a href=\"".url_sid("index.php?f=products&do=detail&id=$id")."\" title=\"$title\">$title</a>";
										echo "</div>";
		                        	}
		                        	echo "<div class=\"clear\"></div>";			
						 			if($total > $perpage) {		
										echo "<div class=\"page fix\">";
										   echo "".paging_theme($total,$pageurl,$perpage,$page)."";
									    echo "</div>";
				                	}
							 	} 
					 	}
		                 else 
						{
							echo "<div style=\"text-align:center;padding-top:10px\">"._PRODUCT_NULL."</div>";
						}
			       echo "</div>";
		       echo "</div>";
		     echo "</div>";
		 }
	     include_once("templates/".$Default_Temp."/rightbody.php");
	 echo "</div>";
	 themeSlideShow(8);
	 themeFooter();
 echo "</div>";
 /*
  * Ket thuc phan san pham
  * 
  */
     
include_once("templates/".$Default_Temp."/footer.php");
echo "<script type=\"text/javascript\">";
		echo "$(function() {";
			echo "$(\".tooltip\").tooltip({";
			echo "bodyHandler: function(){";
				echo "$(\"#tooltip\").css(\"width\", \"auto\");";
				echo "return this.rel;";
			echo "},";
			echo "track: true,";
			echo "showURL: false,";
			echo "extraClass: \"\"";
			echo "});";
		echo "});";
echo "</script>";
echo "<script type=\"text/javascript\" src=\"templates/".$Default_Temp."/js/tooltip.js\"></script><!--Dùng cho trang sản phẩm-->";	
}
?>